﻿<div id="modal" class="modal hide fade" >
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3 class="modal-header-text">Header</h3>
    </div>

    <div class="modal-body">
        <p id="bodyContainer">Body</p>
    </div>
    
    <div class="modal-footer">
        <a href="#" data-dismiss="modal" class="btn">Close</a>
        <a href="#" data-action-button="" class="">Submit</a>
    </div>

</div>

<script>
    $(document).ready(function () {

        var modalBoxUniqueID = ('modal' + (($.guid) + 1).toString());
        $('#modal').attr("id", modalBoxUniqueID);

        $('a[data-modal-url],a[data-modal-url-action], a[data-modal-text]').each(function () {


            var modalUrlAction = $(this).data('modal-url-action');
            if (modalUrlAction != "" && modalUrlAction != null) {
                $('a[data-action-button]').bind('click', function () {

                    $.post(modalUrlAction, function (data) {
                        $('#bodyContainer').html(data);
                        $('#' + modalBoxUniqueID).modal({ show: true, backdrop: 'static' });
                    });
                    $('a[data-action-button]').unbind('click');
                    $('a[data-action-button]').addClass("disabled");
                });
            }
            else {
                var modalUrl = $(this).data('modal-url');
                if (modalUrl != "" && modalUrl != null) {
                    $(this).bind('click', function () {

                        $.get(modalUrl, function (data) {
                            $('#bodyContainer').html(data);
                            $('#' + modalBoxUniqueID).modal({ show: true, backdrop: 'static' });
                        });
                    });
                }
            }

            var modelText = $(this).data('modal-text');
            if (modelText != "" && modelText != null) {
                $(this).bind('click', function () {

                    $('#bodyContainer').html(modelText)
                    $('#' + modalBoxUniqueID).modal({ show: true, backdrop: 'static' });
                });
            }


            $('a[data-dismiss]').click(function () {
                //alert(window.parent.location.href);
                window.parent.location.reload();
            });

            var modalHeader = $(this).data('modal-header');
            if (modalHeader != "" && modalHeader != null) {
                $('.modal-header-text').html(modalHeader);
            } else {
                $('.modal-header-text').html('Information');
            }

            var modalShowFooter = $(this).data('modal-show-footer');
            if (modalShowFooter != "" && modalShowFooter != null && Boolean(modalShowFooter)) {
                modalShowFooter = true;
            }
            if (modalShowFooter){
                $('.modal-footer').show();
            }
            else {
                $('.modal-footer').hide();
            }

            var modalPrimaryActionButtonCss = $(this).data('modal-action-button-css');
            if (modalPrimaryActionButtonCss != "" && modalPrimaryActionButtonCss != null) {
                $('a[data-action-button]').addClass(modalPrimaryActionButtonCss);
            } else {
                $('a[data-action-button]').addClass("btn btn-primary");
            }

            var modalPrimaryActionButtonText = $(this).data('modal-action-button-text');
            if (modalPrimaryActionButtonText != "" && modalPrimaryActionButtonText != null) {
                $('a[data-action-button]').html(modalPrimaryActionButtonText);
            } else {
                $('a[data-action-button]').html('OK');
            }

        });
    });


</script>
